package com.maizijinf;

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.TimeUnit;

/**
 * Created by Germmy on 2016/5/14.
 */
public class Consumer implements  Runnable {

    private BlockingQueue<String> myBq=null;


    public  Consumer(){

    }

    public  Consumer(BlockingQueue<String> myBq){
        this.myBq=myBq;
    }

    public void run() {
        try {
            while (true){
                if (myBq != null) {

                    while (!myBq.isEmpty()){
                        System.out.println(
                                "当前线程ID为:"+Thread.currentThread().getId()+
                                "当前线程Name为:"+Thread.currentThread().getName()
                                +"^_^"+"每一个取到的值为"+myBq.take());
                    }


                }else{
                    System.out.println("myBq空啦");
                }

                try {
                    TimeUnit.MILLISECONDS.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }


        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
